<?php
define('EmpireCMSAdmin','1');
require_once("../class/connect.php");
require_once("../class/db_sql.php");
require_once("../class/functions.php");
require_once("../class/say.php");
require_once("../class/page_obj.php");
$link=db_connect();
$empire=new mysqlquery();
$stime=$_REQUEST["stime"];
$etime=$_REQUEST["etime"];
$city=$_REQUEST["city"];
$time_border_type=$_REQUEST["t_type"];
$type=$_REQUEST["type"];
$orderByCol=$_REQUEST["orderByCol"];
$orderByType=$_REQUEST["orderByType"];

$sql="SELECT * FROM phome_ecms_actives WHERE  checked=1";
if($stime){
	$sql=$sql." AND FROM_UNIXTIME(together_time) >FROM_UNIXTIME('{$stime}')";
}
if($etime){
	$sql=$sql." AND FROM_UNIXTIME(together_time) <=FROM_UNIXTIME('{$etime}')";
}
if($city){
	$sql=$sql." AND target_city ='{$city}'";
}

if($time_border_type){
	if($time_border_type=="-week"){
		$sql=$sql." AND FROM_UNIXTIME(together_time) >".strtotime("-7 day");
	}
	if($time_border_type=="week"){
		$sql=$sql." AND FROM_UNIXTIME(together_time) >".strtotime("+7 day");
	}
	if($time_border_type=="month"){
		$sql=$sql." AND FROM_UNIXTIME(together_time) >".strtotime("+30 day");
	}
}
if($type){
	$sql=$sql." AND active_type ='{$type}'";
}
if($orderByCol && in_array($orderByCol,array('start_time','onclick','together_time'))){
	$sql=($sql." order by $orderByCol ".($orderByType==1?"ASC":"DESC"));
}
$page=$_REQUEST['p'];
$nums=DbTouch('phome_ecms_actives',array("checked"=>'1'),"count(*) as total");
$page=new page_obj($page,array("itemnum"=>10,"border"=>4,"row_count"=>$nums['total']));
$page_start=$page->arr_temp['start'];
$page_end=$page->arr_temp['end'];
$page_current=$page->current_page;
$limit_str=$page->get_limit_str();
$sql=($sql." ".$limit_str);
//echo $sql;
//exit();

$infosql=$empire->query($sql);
$is_run=false;
$index=0;
//print_r($public_r);
while($r=$empire->fetch($infosql))
{
	$is_run=true;
?>
  <li<?php if($index++%2===1){echo " class='li'";};?>>
	  <div class="image"><a href="./myactive/<?php echo $r[newspath];?>/<?php echo $r[id];?>.html"><img src="<?php if($r[active_cover]){echo getImgSizeUrl($r[active_cover],119,105);}else{echo $public_r[newsurl]."skin/default/image/img01.jpg";}?>" width="350" alt="<?php echo $r[oldtitle];?>" title="<?php echo $r[oldtitle];?>" /></a></div>
	   <dl>
		  <dt><a href="<?=$public_r[newsurl]?>act/detail/?id=<?=$r[id]?>" title="<?php echo $r[title];?>"><?php echo $r[title];?></a></dt>
		  <dd>
			 <p>发 起 人：<a href="<?=$public_r[newsurl]?>/?uid=<?php echo $r[adduserid];?>" title="<?php echo $r[adduser];?>"><?php echo $r[adduser];?></a></p>
			 <p>活动分类：<?php echo $r[active_type];?></p>
			 <p>活动地点：<?php echo $r[address];?></p>
			 <p>活动时间：<?php echo $r[together_time];?></p>
			 <p>关注程度：<?php echo $r[focus];?>人浏览</p>
		  </dd>
	   </dl>
	   <div class="clear"></div>
  </li>

<?php
}
if($is_run){
echo "<div><ul class='page-list'>";
for( $i=$page_start;$i<=$page_end;$i++){
	echo "<li style='height:20px;'><span class=".($i==$page_current?"current":"page")." onclick='loadHtml(\"{$i}\")'>{$i}</span></li>";
}
echo "</ul></div>";
}
?>
<?php
if(!$is_run){echo "<li><div class='no-data'>暂无数据！</div></li>";}
?>